package com.liming.salesman.core;


import com.liming.core.impl.biz.GenericBizServiceImpl;
import com.liming.salesman.api.biz.ISalesmanBeanService;
import com.liming.salesman.api.dao.ISalesmanBeanDao;
import com.liming.salesman.api.persistence.ISalesmanBean;
import com.liming.salesman.entities.SalesmanBeanImpl;

import java.util.List;

/**
 * Created by dell on 14-1-17.
 */
public class SalesmanBeanServiceImpl extends GenericBizServiceImpl implements ISalesmanBeanService {
    private ISalesmanBeanDao salesmanBeanDao;

    public void setSalesmanBeanDao(ISalesmanBeanDao salesmanBeanDao) {
        this.salesmanBeanDao = salesmanBeanDao;
        super.init(salesmanBeanDao, SalesmanBeanImpl.class.getName());
    }

    public void init() {
    }

    @Override

    public ISalesmanBean addSalesman(ISalesmanBean salesman) {
        return salesmanBeanDao.saveSalesman(salesman);
    }

    @Override


    public List<ISalesmanBean> getAllSalesman() {
        return salesmanBeanDao.getAll(SalesmanBeanImpl.class.getName());
    }

    @Override
    public int login(String username, String password) {
        ISalesmanBean user = salesmanBeanDao.getSalesman(username);
        if (user == null) {
            return (USERNAME_NOT_EXIST);
        }
        if (encrypt(password).equals(user.getPassword())) {
            return (SUCCESS);
        } else {
            return (PASSWORD_ERROR);
        }
    }

    private String encrypt(String text) {

        return text;
    }
}
